<template>
	<view class="SubmitOrder">
		<topbar-submit-order></topbar-submit-order>
		<scroll-view scroll-y="true" class="scroll-Y">
			<!-- 地址 -->
			<view class="SubmitOrderAddress">
				<view class="changeAddress" @click="changeAddress">选择地址<u-icon name="arrow-right" color="#9d9e9e" size="28"></u-icon></view>
				<Address :address="defaultAddress"></Address>
			</view>
			<u-popup v-model="showAddress" mode="bottom"  height="50%" :closeable='true'>
				<list-address :addressList = "address" :defaultAddress="defaultAddress" @isAddressChange="isAddressChange"></list-address>
			</u-popup>
			<!-- 订单 -->
			<order-list :OrderList="OrderList" :orderTime="orderTime"></order-list>
		</scroll-view>
		<u-button hover-class="none" shape="circle" :custom-style="commitMall" @click="submitOrder">立即结算</u-button>
	</view>
</template>

<script>
	import {getOrderPay,getOrderAddress,postPay} from "network/orderMsg.js"
	
	import TopbarSubmitOrder from "./childSubmitOrder/TopbarSubmitOrder.vue"
	import ListAddress from "./childSubmitOrder/ListAddress.vue"
	import OrderList from "./childSubmitOrder/OrderList.vue"
	
	import Address from "components/content/Address.vue"
	
	export default{
		onLoad(option) {
			this.sids = option.sids
			getOrderPay(option.sids).then(res=>{
				this.OrderList = res.data.result
			})
			this.orderTime = option.time
			getOrderAddress().then(res=>{
				if(res.data.code !== 20000){
					uni.showToast({
					    title: res.data.msg,
					    duration: 2000,
						icon:'none'
					})
				}else{
					this.address = res.data.result
					res.data.result.forEach(e=>{
						if(e.isDefault == 1) return this.defaultAddress = e
					})
				}
			})
		},
		components:{
			TopbarSubmitOrder,
			Address,
			ListAddress,
			OrderList
		},
		data() {
			return {
				commitMall:{
					color: "#FFFFFF",
					width:"90%",
					fontSize: "30rpx",
					backgroundColor:"#0C34BA",
					margin: "0rpx 40rpx",
					position: "fixed",
					bottom: "20rpx"
				},
				address:[],
				defaultAddress:null,
				showAddress:false,
				OrderList:[],
				orderTime:"",
				sids:""
			}
		},
		methods:{
			changeAddress(){
				this.showAddress = true
			},
			isAddressChange(e){
				this.defaultAddress = e
			},
			submitOrder(){
				
				let address = this.defaultAddress.province+this.defaultAddress.city+this.defaultAddress.county
				let phone = this.defaultAddress.tel
				let receiver = this.defaultAddress.name
				postPay(this.sids,phone,address,receiver).then(res=>{
					if(res.data.code == 60000){
						uni.showToast({
						    title: res.data.msg,
						    duration: 2000,
							icon:'none'
						})
						setTimeout(()=>{
							uni.navigateTo({
								url:"../../../mine/childMine/myOrder/MyOrder"
							})
						},1000)
					}
				})
			}
		}
	}
</script>

<style scoped>
	.SubmitOrder{
		height: 97vh;
		position: relative;
		width: 100%;
	}
	.scroll-Y{
		position: absolute;
		top: 105rpx;
		bottom: 100rpx;
		left: 0rpx;
		right: 0rpx;
		width: 90%;
		margin: 0rpx 40rpx;
	}
	.SubmitOrderAddress{
		margin-top: 40rpx;
	}
	.SubmitOrderAddress>.changeAddress{
		margin-bottom: 20rpx;
	}
</style>
